/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
 *
 * @author Administrator
 */
public class HelpCanvas extends Canvas {

    Display display;
    NinjaRunMidlet midlet;
    Image imgBackground;
    Image imgBackEnOff;
    Image imgBackEnOn;
    ButtonImage btnBackEn;
//--- gesture ---    
    int x;
    int y;
//--- end-gesture ---

    public HelpCanvas(NinjaRunMidlet midlet, Display display) {
        setFullScreenMode(true);
        this.midlet = midlet;
        this.display = display;
        try {
            imgBackEnOff = Image.createImage("/jtkpolban/kartikawindy/kasund/resources/sd_back_en_off.png");
            imgBackEnOn = Image.createImage("/jtkpolban/kartikawindy/kasund/resources/sd_back_en_on.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        int xyArea[] = new int[4];
        //int width = getWidth() / 2 - (imgPlayIdOff.getWidth() / 2);
        //int height = getHeight() / 2;
        int hBack = 0;//getWidth() - imgMineIdOff.getWidth();
        int wBack = getHeight() - imgBackEnOff.getHeight();

        xyArea[0] = wBack; //x1
        xyArea[1] = wBack + imgBackEnOff.getWidth(); //x2
        xyArea[2] = hBack; //y1
        xyArea[3] = hBack + imgBackEnOff.getHeight(); //y2
        btnBackEn = new ButtonImage("backEn", imgBackEnOff, imgBackEnOn,
                imgBackEnOff, hBack,
                wBack, xyArea, Graphics.TOP | Graphics.LEFT);

    }

    protected void paint(Graphics g) {
        g.setColor(0xFFFFFF);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(0x0000FF);
        g.drawString("  Learn Canvas", 0, 20,
                Graphics.TOP | Graphics.LEFT);
        btnBackEn.paint(g);
    }

    protected void keyPressed(int keyCode) {
        System.out.println(keyCode);

        if (keyCode == -6) {
            midlet.showMenuCanvas();
        }
        repaint();
    }

    protected void pointerPressed(int x, int y) {
        this.x = x;
        this.y = y;

        if (x > btnBackEn.xImage
                && x < (btnBackEn.xImage + btnBackEn.imageWidth)
                && y > btnBackEn.yImage
                && y < (btnBackEn.yImage + btnBackEn.imageHeight)) {
            btnBackEn.pointerPressed(x, y);
        }

        repaint();
    }

    protected void pointerDragged(int x, int y) {
        this.x = x;
        this.y = y;

        if (x > btnBackEn.xImage
                && x < (btnBackEn.xImage + btnBackEn.imageWidth)
                && y > btnBackEn.yImage
                && y < (btnBackEn.yImage + btnBackEn.imageHeight)) {
            btnBackEn.pointerDragged(x, y);
        }

        repaint();
    }

    protected void pointerReleased(int x, int y) {
        this.x = x;
        this.y = y;

        if (x > btnBackEn.xImage
                && x < (btnBackEn.xImage + btnBackEn.imageWidth)
                && y > btnBackEn.yImage
                && y < (btnBackEn.yImage + btnBackEn.imageHeight)) {
            btnBackEn.pointerReleased(x, y);
            midlet.showMenuCanvas();
        }
        repaint();
        //scroll
    }
}
